package com.lz.fruitday.widget;


        import android.annotation.TargetApi;
        import android.content.Context;
        import android.os.Build;
        import android.view.View;

        import android.widget.LinearLayout;
        import android.util.AttributeSet;
        import android.view.LayoutInflater;
        import android.widget.RadioButton;
        import android.widget.RadioGroup;
        import android.widget.TextView;

        import com.lz.fruitday.R;
        import com.lz.fruitday.fragment.FoodFragment;


/**
 * Created by liuZhi
 * 2015/10/22
 */
public class TitleBar extends LinearLayout {

    private TextView tvLeft;
    private RadioGroup barRg;
    private TextView tvRight;
    private RadioButton leftBut;
    private RadioButton rightBut;

    public TitleBar(Context context) {
        super(context);
        initView();
    }
    public TitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }
    public TitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        LayoutInflater inflater= (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(R.layout.widget_titlebar_layout,this,false);
        this.addView(view);
        tvLeft = (TextView) view.findViewById(R.id.tv_left);
        barRg = (RadioGroup) view.findViewById(R.id.bar_rg);
        leftBut = (RadioButton) view.findViewById(R.id.left_btn);
        rightBut = (RadioButton) view.findViewById(R.id.right_btn);
        tvRight = (TextView) view.findViewById(R.id.tv_right);
    }
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public void showHomeView(){
        tvLeft.setVisibility(VISIBLE);
        tvLeft.setText("武汉");
        tvLeft.setCompoundDrawablesRelativeWithIntrinsicBounds(getContext().getResources().getDrawable(R.mipmap.bar_location), null, null, null);
        leftBut.setVisibility(VISIBLE);
        leftBut.setText("天天果园");
        rightBut.setText("天天到家");
        tvRight.setVisibility(VISIBLE);
        tvRight.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, getContext().getResources().getDrawable(R.mipmap.bar_search_default),null);
    }
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public void showKindView(){
        tvLeft.setVisibility(INVISIBLE);
        leftBut.setVisibility(GONE);
        rightBut.setChecked(false);
        rightBut.setText("品类");
        tvRight.setVisibility(VISIBLE);
        tvRight.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, getContext().getResources().getDrawable(R.mipmap.bar_search_default),null);
    }
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public  void showGarden(){
        tvLeft.setVisibility(INVISIBLE);
        leftBut.setVisibility(GONE);
        rightBut.setChecked(false);
        rightBut.setText("我的果园");
        tvRight.setVisibility(VISIBLE);
        tvRight.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, getContext().getResources().getDrawable(R.mipmap.icon_vip), null);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public void showShopCar(){
        tvLeft.setVisibility(INVISIBLE);
        leftBut.setVisibility(GONE);
        rightBut.setText("购物车");
        tvRight.setVisibility(VISIBLE);
        tvRight.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, getContext().getResources().getDrawable(R.mipmap.bar_delete), null);
    }
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public void showFood(){
        tvLeft.setVisibility(VISIBLE);
        tvLeft.setCompoundDrawablesRelativeWithIntrinsicBounds(getContext().getResources().getDrawable(R.mipmap.bar_myguoshi), null, null, null);
        leftBut.setVisibility(VISIBLE);
        leftBut.setText("百科");
        rightBut.setText("果友圈");
        tvRight.setVisibility(VISIBLE);
        tvRight.setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, getContext().getResources().getDrawable(R.mipmap.bar_guoshizhuanti),null);
    }

    public TextView getTvLeft() {
        return tvLeft;
    }

    public void setTvLeft(TextView tvLeft) {
        this.tvLeft = tvLeft;
    }

    public RadioGroup getBarRg() {
        return barRg;
    }

    public void setBarRg(RadioGroup barRg) {
        this.barRg = barRg;
    }

    public TextView getTvRight() {
        return tvRight;
    }

    public void setTvRight(TextView tvRight) {
        this.tvRight = tvRight;
    }

    public RadioButton getLeftBut() {
        return leftBut;
    }

    public void setLeftBut(RadioButton leftBut) {
        this.leftBut = leftBut;
    }

    public RadioButton getRightBut() {
        return rightBut;
    }

    public void setRightBut(RadioButton rightBut) {
        this.rightBut = rightBut;
    }
}
